package 网络编程;

import thread.ClientReceiveThread;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws Exception{
        Socket socket = new Socket("127.0.0.1", 6789);
        
        Scanner scanner = new Scanner(System.in);
        Thread clientReceiveThread = new ClientReceiveThread(socket);
        clientReceiveThread.start();
        try {
            OutputStream outputStream = socket.getOutputStream();
            DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
            while (true) {
                String s = scanner.nextLine();
                if ("exit".equals(s)) {
                    dataOutputStream.close();
                    socket.close();
                    break;
                }
                dataOutputStream.writeUTF(s);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
